home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#02 (Apr85-Jul85)
/
modula 2
/
modula Vol. 1 #7
/
HanoiGraphic.MOD
Wrap
Text File
|
1985-04-14
|
4KB
|
138 lines
MODULE Hanoi;
(* build starting position for Hanoi Towers *)
FROM Terminal IMPORT ClearScreen;
FROM InOut IMPORT WriteString, ReadCard, WriteLn;
(* data structures for Quickdraw calls *)
TYPE
VHSelect = (v,h);
Point = RECORD
CASE INTEGER OF
0: v: INTEGER;
h: INTEGER;
|1: vh: ARRAY VHSelect OF INTEGER;
END; (* CASE *)
END; (* RECORD *)
Rect = RECORD
CASE INTEGER OF
0: top: INTEGER;
left: INTEGER;
bottom: INTEGER;
right: INTEGER;
|1: topLeft: Point;
botRight: Point;
END; (* CASE *)
END; (* RECORD *)
CONST
CX = 355B;
QuickDraw1ModNum = 2; (* absolute module number
of QuickDraw1 *)
VAR
r: Rect; NumDisks: CARDINAL;
PROCEDURE SetRect (VAR r: Rect; left,top,right,bottom: INTEGER);
CODE CX; QuickDraw1ModNum; 51 END SetRect;
PROCEDURE PaintRect (r: Rect);
CODE CX; QuickDraw1ModNum; 62 END PaintRect;
PROCEDURE PaintRoundRect(r: Rect; ovWd, ovHt: INTEGER);
CODE CX; QuickDraw1ModNum; 67 END PaintRoundRect;
PROCEDURE DrawBase;
CONST
BaseLeft = 36;
BaseTop = 261;
BaseRight = 476;
BaseBottom = 270;
BEGIN
SetRect(r,BaseLeft,BaseTop,BaseRight,BaseBottom);
PaintRect(r);
END DrawBase;
PROCEDURE DrawPosts;
CONST
PostTop = 144;
PostBottom = 261;
PostWidth = 6;
HalfPostWidth = PostWidth DIV 2;
PostPosition = 128;
VAR
n, PostLeft, PostRight: INTEGER;
BEGIN
n:=1;
WHILE n <= 3 DO
PostLeft := (PostPosition * n) - HalfPostWidth;
PostRight := PostLeft + PostWidth;
SetRect(r,PostLeft,PostTop,PostRight,PostBottom);
PaintRect(r);
n:= n + 1;
END; (* WHILE *)
END DrawPosts;
PROCEDURE DrawVarDisks(numberofdisks: CARDINAL);
CONST
bigdiskleft = 128 - 60;
bigdisktop = 261 - 12;
bigdiskright = 128 + 60;
bigdiskbottom = 261;
deltalength = 5;
deltadepth = 12;
VAR leftedge, topedge, rightedge, bottomedge: INTEGER;
i: CARDINAL;
BEGIN
IF (numberofdisks > 2) AND (numberofdisks < 10)
THEN
leftedge := bigdiskleft; topedge := bigdisktop;
rightedge := bigdiskright; bottomedge := bigdiskbottom;
SetRect(r,leftedge,topedge,rightedge,bottomedge);
PaintRoundRect(r,40,40);
FOR i := 1 TO numberofdisks - 1 DO
leftedge := leftedge + deltalength;
topedge := topedge - deltadepth;
rightedge := rightedge - deltalength;
bottomedge := bottomedge - deltadepth;
SetRect(r,leftedge,topedge,rightedge,bottomedge);
PaintRoundRect(r,40,40);
END; (* FOR *)
END; (* IF *)
END DrawVarDisks;
PROCEDURE GetInput(VAR NDisks: CARDINAL);
BEGIN
ClearScreen;
WriteString("Enter number of disks (between 3 to 9)");
WriteLn;
WriteString("To quit - enter number out of range");
ReadCard(NDisks);
ClearScreen;
END GetInput;
PROCEDURE InitGraphics(NumberofDisks: CARDINAL);
BEGIN
DrawBase;
DrawPosts;
DrawVarDisks(NumberofDisks);
END InitGraphics;
PROCEDURE ExecuteTowers;
VAR Delay: CARDINAL;
BEGIN
FOR Delay := 1 TO 30000 DO END; (* FOR *)
END ExecuteTowers;
BEGIN
GetInput(NumDisks);
WHILE (NumDisks >= 3) AND (NumDisks <= 9) DO
InitGraphics(NumDisks);
ExecuteTowers;
GetInput(NumDisks);
END; (* WHILE *)
END Hanoi.